package cn.edu.zut.internship.web.controller.evaluation;

import cn.edu.zut.internship.bean.sys.Result;
import cn.edu.zut.internship.bean.sys.SysUser;
import cn.edu.zut.internship.iservice.evaluation.EvaluationSV;
import cn.edu.zut.internship.web.utils.UserInfoUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/evaluation")
public class EvaluationController {
    @Reference
    EvaluationSV evaluationSV;

    /**
     * 查询实训单位的评论
     * @param params
     * @return
     */
    @RequestMapping("/getEvaluationList")
    public Result getEvaluationList(@RequestBody Map params) {
        Result result = new Result();
        if(params.get("companyId") instanceof String){
            Long companyId = Long.valueOf((String) params.get("companyId"));
            params.put("companyId",companyId);
        }
        result = evaluationSV.selectEvaluation(params);
        return result;
    }

    /**
     * 获取评论详情
     * @param params
     * @return
     */
    @RequestMapping("/getEvaluation")
    public Result getEvaluation(@RequestBody Map params) {
        Result result = new Result();
        Long evaluationId = Long.valueOf((String) params.get("evaluationId"));
        result = evaluationSV.getEvaluationById(evaluationId);
        return result;
    }


    /**
     * 新增父级评论
     *
     * @param params
     * @return
     */
    @RequestMapping("/addPersonEvaluation")
    public Result addPersonEvaluation(@RequestBody Map params) {
        Result result = new Result();
        SysUser userInfo = UserInfoUtil.getUserInfo();
        params.put("userAccount",userInfo.getUserAccount());
        result = evaluationSV.addPersonEvaluation(params);
        return result;
    }

    /**
     * 新增子评论
     *
     * @param params
     * @return
     */
    @RequestMapping("/addSonEvaluation")
    public Result addSonEvaluation(@RequestBody Map params) {
        Result result = new Result();
        SysUser userInfo = UserInfoUtil.getUserInfo();
        params.put("userAccount",userInfo.getUserAccount());
        result = evaluationSV.addSonEvaluation(params);
        return result;
    }

    /**
     * 修改评论
     * @param params
     * @return
     */
    @RequestMapping("/updateEvaluation")
    public Result updateEvaluation(@RequestBody Map params) {
        Result result = new Result();
        result = evaluationSV.updataEvaluation(params);
        return result;
    }

    /**
     * 删除评论
     *
     * @param params
     * @return
     */
    @RequestMapping("/deleteEvaluation")
    public Result deleteEvaluation(@RequestBody Map params) {
        Result result = new Result();
        result = evaluationSV.delectEvaluation(params);
        return result;
    }

    @RequestMapping("/addLikeNum")
    public Result addLikeNum(@RequestBody Map params) {
        Result result = new Result();
        SysUser userInfo = UserInfoUtil.getUserInfo();
        params.put("userAccount",userInfo.getUserAccount());
        result = evaluationSV.addLikeNum(params);
        return result;
    }

    @RequestMapping("/cancelLikeNum")
    public Result cancelLikeNum(@RequestBody Map params) {
        Result result = new Result();
        result = evaluationSV.cancelLikeNum(params);
        return result;
    }


}
